<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
  <style>
      body {
          margin:0;
          padding:0
      }
    ul,li{
      list-style-type: none;
      margin:0;
      padding:0
    }
    li{
      display: block;
      padding:10px 20px;
      background:#aaa;
      color:#fff;
      border-radius: 5px;
      margin-top:20px;
      text-align: center;
    }
  </style>
  <title>window.webkit.messageHandlers</title>
  
  <script>
      // 获取到devideId回调
      var globalCallback = function(devideId) {
          document.getElementById('deviceIdLabel').innerHTML = devideId;
          return 'jsReturnMsg';
      }
  </script>
  
</head>
<body>
<ul>
  <li onclick="popAlertPanel()">弹提示框</li><br>
  
  <li onclick="popConfirmPanel()">弹确认框</li><br>
  <label id="confirmAlert"> 是否点击了确认?? </label><br>
  
  <li onclick="popTextInputPanel()">弹输入框</li><br>
  <label id="textFieldAlert"> 手机号是多少? </label><br>
  
  <li onclick="getDeviceId()">获取设备ID</li><br>
  <label id="deviceIdLabel"> 设备 ID 是多少? </label><br>
  
</ul>
<div id="temp"></div>

<script>
  // 弹提示框
  function popAlertPanel() {
      alert("提示框");
  }
  // 弹确认框
  function popConfirmPanel() {
      var ok = confirm("确认框");
      document.getElementById('confirmAlert').innerHTML = ok;
  }
  // 弹输入框
  function popTextInputPanel() {
      
      var tel = prompt("输入框","请输入手机号");
      
      document.getElementById('textFieldAlert').innerHTML = tel;
  }

  // 获取设备ID
  function getDeviceId() {
      // NSString *const LMJOCJSHelperScriptMessageHandlerName1_ = @"OCJSHelper1";
      // 注册了 OCJSHelper1 message.name
      window.webkit.messageHandlers.OCJSHelper1.postMessage({code: 'getDeviceId', functionName: 'globalCallback'});
  }

</script>
</body>
</html>
